package com.example.socket.longlink;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.*;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;

/**
 * @author hej
 * @date 2024/9/11 18:47
 */
public class LongConnectionClient {
    public static void main(String[] args) {
        String serverAddress = "127.0.0.1";
        int port = 12345;

        try {
            Socket socket = new Socket(serverAddress, port);
            System.out.println("已连接到服务器：" + serverAddress + " 端口：" + port);
            DataInputStream in = new DataInputStream(socket.getInputStream());
            //FileWriter fileWriter = new FileWriter("wowowo.xml");
            while (true) {
                String xmlLine = "";
                byte[] buf = new byte[1024];
                int tag = in.read(buf);
                if (tag != -1) {
                    System.out.println(new String(buf, 0, tag));
                    xmlLine += new String(buf, 0, tag);
                }
                //fileWriter.write(xmlLine);
                System.out.println("XML文件保存成功！");
            }
            //in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }   catch (Exception e) {
            e.printStackTrace();
        }
    }


}
